const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  chainWebpack: (config) => {
    config.resolve.alias // 添加别名
      .set('@', resolve('src'))
    // 发布时移除console
    config.optimization.minimizer('terser').tap((args) => {
      const compress = args[ 0 ].terserOptions.compress

      compress.drop_console = true
      compress.pure_funcs = [
        '__f__', // App 平台 vue 移除日志代码
      ]
      return args
    })
  },
  configureWebpack: {
    plugins: [
      new CopyWebpackPlugin([
        {
          from: resolve('cloudfunctions'),
          to: resolve(`dist/${ process.env.NODE_ENV === 'production' ? 'build' : 'dev' }/${ process.env.UNI_PLATFORM }/cloudfunctions`)
        }
      ])
    ]
  }
}
